package com.test.practice.io.transitionstream;

import lombok.Cleanup;

import java.io.*;

/**
 * 处理流---转换流--字符流的一种Demo
 *
 * @Description: 处理流---转换流Demo
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-10
 * =======================
 * @Version: 1.1.2.0
 */
public class TransitionStreamDemo {

    public static void main(String[] args) throws Exception {

        FileInputStream fis = new FileInputStream("1.txt");
        FileOutputStream fos = new FileOutputStream("gbk.txt");


        //源文件保存时按照gbk保存的
        @Cleanup InputStreamReader isr = new InputStreamReader(fis,"gbk");
        //新文件查看时通过转码使用utf-8读取
        @Cleanup OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8");

        char[] datas = new char[1024];

        int len;

        while((len = isr.read(datas))!=-1){
            osw.write(datas, 0, len);
        }

    }
}
